useLazyMethod
Same behavior as useMethod excepts it is not called when the component first renders
export const LoginComponent = () => {
const shoesService = useService('auth')
const {
isLoading,
isError,
isSuccess,
isCalled,
error,
call: login,
data,
} = useLazyMethod(authService.login)
if (!isCalled || !isLoading) {
return <Loader>
}
return <button onClick={login}>login</button>
}
It can also be used in one line by using the method string
export const LoginComponent = () => {
const {
isLoading,
isError,
isSuccess,
isCalled,
error,
call,
data,
} = useLazyMethod('authService.login')
if (!isCalled || !isLoading) {
return <Loader>
}
return <button onClick={login}>login</button>
}